package entity;

/**
 * @author clear
 * @version 1.0
 * @description: TODO
 * @date 2023/11/22 10:21
 */
public class Single {

    //为了使new对象时是有序的，这里加上volatile关键字
    public static volatile Single instance = null;

    //构造方法私有化，避免被其他类实例
    private Single(){}

    //其他类通过getInstance()进行调用该类的实例
    public static Single getInstance() {
        synchronized (Single.class) {
            if (instance == null){
                return new Single();
            }
        }
        return instance;
    }

}
